package com.heima.wemedia.controller;

import com.heima.model.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.common.GetUserId;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2023/1/11 22:58
 */
@RestController
@RequestMapping("/api/v1/news")
@Slf4j
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * @description 查询文章
     * @param dto
     * @return com.heima.model.dtos.ResponseResult
     * @author 31115
     * @date 2023/1/12 13:36
     */
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto){
        Integer userId = GetUserId.getUserId();
        return wmNewsService.findAll(userId,dto);
    }

    /**
     * @description 修改、新增、新增草稿到文章表
     * @param dto
     * @return com.heima.model.dtos.ResponseResult
     * @author 31115
     * @date 2023/1/12 13:38
     */
    @PostMapping("/submit")
    public  ResponseResult submit(@RequestBody WmNewsDto dto){
        Integer userId = GetUserId.getUserId();
        return wmNewsService.submit(userId,dto);
    }

}
